package com.demo.index;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo.common.model.Article;
import com.demo.controller.BaseController;
import com.jfinal.plugin.activerecord.Page;

/**
 * IndexController
 */
public class IndexController extends BaseController<Article> {
	//首页
	public void index() {
		//文章
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("whereSql", "");
		
		Page<Article> page = Article.me.paginate(getParaToInt(0,1), 10,map);
		List<Article> atList = page.getList();
		List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
		for(Article at :atList){
			Map<String, Object> entry = new HashMap<String, Object>();
			entry.put("id", at.get("id"));
			entry.put("title", at.get("title"));
			entry.put("content", at.get("content"));
			entry.put("create_date", at.get("create_date"));
			entry.put("read_count", at.get("read_count"));
			entry.put("image_url", at.get("image_url"));
			entry.put("categories", Article.me.getCategories(at));
			//entry.put("tags",  Article.me.getTags(at));
			result.add(entry);
		}
		setAttr("page", new Page(result, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow()));
		render("/index.html");
	}
	 
}





